<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.io.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%!
	//request.setCharacterEncoding("UTF-8");
	String room_id="";       
 	String customer_card="";
    String in_date="";
    String number = "";
    String price_1 = "";
    String price_2 = "";
    String price_3 = "";
%>
<%
 	boolean isMultipart = ServletFileUpload.isMultipartContent(request);
 	if (!isMultipart) {} 
 	else {
 		FileItemFactory factory = new DiskFileItemFactory();
   		ServletFileUpload upload = new ServletFileUpload(factory);
   		List items = null;
   		try {
   			items = upload.parseRequest(request);
   		} catch (FileUploadException e) {
   			e.printStackTrace();
   		}		
   	Iterator itr = items.iterator();
   	while (itr.hasNext()) {
   		FileItem item = (FileItem) itr.next();
   		if (item.isFormField())
   		{
   			String tmp = item.getFieldName();
            String value = new String(item.getString().getBytes("ISO-8859-1"), "UTF-8");
            if(tmp.equals("room_id")) room_id=value;
           	if(tmp.equals("customer_card")) customer_card=value;                         
			if(tmp.equals("in_date")) in_date=value;    
			if(tmp.equals("number")) number=value;  
			if(tmp.equals("price_1")) price_1=value;  
			if(tmp.equals("price_2")) price_2=value;  
			if(tmp.equals("price_3")) price_3=value;  
			
   		} else
   		{
    		}
   		}
   	}
 	
	Class.forName("com.mysql.jdbc.Driver");
	Connection con = null;
	Statement smt = null;
	ResultSet rst = null;
	String SQL = null;
	int i = 0;
	if (room_id.length() == 0 || customer_card.length() == 0 || in_date.length() == 0|| 
			number.length() == 0 || price_1.length() == 0||
			price_2.length() == 0 || price_3.length() == 0 ) response.sendRedirect("add_ru.jsp");
	else
	try {
		String username = "root";
		String password = "Vietyeutam1112";
		String url = "jdbc:mysql://127.0.0.1:3306/ghmotel?useUnicode=true&characterEncoding=UTF-8";
		con = DriverManager.getConnection(url, username, password);
		System.out.println("Da ket noi CSDL");
		smt = con.createStatement();
		rst = smt.executeQuery("select * from service");
		while (rst.next()) i++;
		System.out.println(i);
		i++;
		//SQL = "INSERT INTO product VALUES ('%s','%s','%s')";
// 		SQL = String.format("INSERT INTO service(service_name,service_price,service_number) VALUES ('%s',%s,%s)",service_name,service_price,service_number);
		System.out.println(SQL);
		smt.execute(SQL);
		con.close();
		System.out.println("Dong ket noi");
		response.sendRedirect("service_manager.jsp");
	}
	catch (Exception e) {
		e.printStackTrace();
		System.out.println("KHONG KET NOI DUOC");
	}

%>
</body>
</html>